﻿using System;
using System.Reflection.Emit;
using Sigil.Impl;

namespace Sigil
{
	public partial class Emit<DelegateType>
	{
		/// <summary>
		/// Pushes the size of the given value type onto the stack.
		/// </summary>
		public Emit<DelegateType> SizeOf<ValueType>()
				where ValueType : struct
		{
			return SizeOf(typeof(ValueType));
		}

		/// <summary>
		/// Pushes the size of the given value type onto the stack.
		/// </summary>
		public Emit<DelegateType> SizeOf(Type valueType)
		{
			if (valueType == null)
			{
				throw new ArgumentNullException("valueType");
			}

			if (!valueType.IsValueType)
			{
				throw new ArgumentException("valueType must be a ValueType");
			}

			UpdateState(OpCodes.Sizeof, valueType, Wrap(StackTransition.Push<Int32>(), "SizeOf"));

			return this;
		}
	}
}